$(function() {
	var address='';
	var allmap = $("#allmap");
	var map = new BMap.Map("allmap");
	map.enableScrollWheelZoom(true);
//	var point = new BMap.Point(116.331398,39.897445);
//	map.centerAndZoom(point,12);

	var geolocation = new BMap.Geolocation();
	geolocation.getCurrentPosition(function(r){
		if(this.getStatus() == BMAP_STATUS_SUCCESS){
			var mk = new BMap.Marker(r.point);

//			alert('您的位置：'+r.point.lng+','+r.point.lat);


			var gps_j = localStorage.gpsj;
	var gps_w = localStorage.gpsw;
			var point = new BMap.Point(gps_j, gps_w);
	map.centerAndZoom(point, 13);

	var circle = new BMap.Circle(point, 5000, {
		fillColor: "blue",
		strokeWeight: 1,
		fillOpacity: 0.3,
		strokeOpacity: 0.3
	});
	map.addOverlay(circle);





		var geoc = new BMap.Geocoder();
			map.addOverlay(mk);
		map.panTo(r.point);
		geoc.getLocation(r.point, function(rs){
			var addComp = rs.addressComponents;
			address = addComp.province + addComp.city + addComp.district  + addComp.street  + addComp.streetNumber;
		});

	function showInfo(e) {
		var pt = e.point;
		geoc.getLocation(pt, function(rs){
			var addComp = rs.addressComponents;
			address = addComp.province + addComp.city + addComp.district  + addComp.street  + addComp.streetNumber;
		});


						map.clearOverlays();
						var new_point = new BMap.Point(e.point.lng, e.point.lat);
						var marker = new BMap.Marker(new_point); // 创建标注

						map.addOverlay(marker);

						map.panTo(new_point);
						newGpsJ = e.point.lng;
						newGpsW = e.point.lat;
							var circle = new BMap.Circle(point, 5000, {
		fillColor: "blue",
		strokeWeight: 1,
		fillOpacity: 0.3,
		strokeOpacity: 0.3
	});
	map.addOverlay(circle);
					}
					map.addEventListener("click", showInfo);



		}

		else {
			alert('failed'+this.getStatus());
		}
	},{enableHighAccuracy: true})

			$('.back').on('click', function() {
				localStorage.map_address = address;

			history.back(-1)
		});

});
